#ifndef TREEWIDGET_H
#define TREEWIDGET_H

#include <QTreeWidget>
#include <QHeaderView>

class QMouseEvent;


class TreeWidget : public QTreeWidget {

        Q_OBJECT

    public:
        explicit TreeWidget(QWidget *parent = 0);

        /*! Returns a string with toplevel item's text
          for currently selected item. Example:
           - foo
             - item1
             - item2 <- selected
             - item3
          so "foo" is returned.
          QString() (null) is returned if there is not any selection
          */
        QString currentTopLevelText(int column=0);

    protected:
        void mousePressEvent(QMouseEvent *event);
        void keyPressEvent(QKeyEvent *event);

    signals:
        // These signals are emitted in "their events", they are easier to use then.
        void mousePressed(QMouseEvent *event);
        void keyPressed(QKeyEvent *event);

};


/*! Custom QTreeWidget horizontal header to allow
  configuration of column visibility.

  It breaks object paradigm a bit as it's dependent
  on parent instance if TreeWidget. So there is always
  1:1 relation for EditableTreeHeader and TreeWidget
  instances.
  */
class EditableTreeHeader : public QHeaderView {
        Q_OBJECT

    public:
        //! \note Parent has to be set as it's used for custom context menu
        EditableTreeHeader(TreeWidget *parent);

    private slots:
        void customContextMenu(const QPoint &point);
        void columnActionHandler();

    private:
        QMenu *m_menu;
        TreeWidget *m_parent;
};


#endif // TREEWIDGET_H
